import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)



/* Layout */
import Layout from '@/views/layout/Layout'


const login = r => require.ensure([], () => r(require('@/views/login/index')), 'login');
const home = r => require.ensure([], () => r(require('@/views/home/index')), 'home');
const register = r => require.ensure([], () => r(require('@/views/home/register/index')), 'register');
const taskManage = r => require.ensure([], () => r(require('@/views/taskManage/index')), 'taskManage');
const taskHistory = r => require.ensure([], () => r(require('@/views/taskManage/taskHistory/index')), 'taskHistory');
const taskEntry = r => require.ensure([], () => r(require('@/views/taskManage/taskEntry/index')), 'taskEntry');
const taskEntryItem = r => require.ensure([], () => r(require('@/views/taskManage/taskEntry/taskEntryItem/index')), 'taskEntryItem');
const taskProgress = r => require.ensure([], () => r(require('@/views/taskManage/taskProgress/index')), 'taskProgress');
const taskMine = r => require.ensure([], () => r(require('@/views/taskManage/taskMine/index')), 'taskMine');
const userManage = r => require.ensure([], () => r(require('@/views/userManage/index')), 'userManage');
const userList = r => require.ensure([], () => r(require('@/views/userManage/userList/index')), 'userList');
const leaderManage = r => require.ensure([], () => r(require('@/views/userManage/userList/leaderManage/index')), 'leaderManage');
const materialManage = r => require.ensure([], () => r(require('@/views/userManage/materialManage/index')), 'materialManage');
const costManage = r => require.ensure([], () => r(require('@/views/userManage/costManage/index')), 'costManage');
const brandManage = r => require.ensure([], () => r(require('@/views/userManage/brandManage/index')), 'brandManage');
const reportManage = r => require.ensure([], () => r(require('@/views/reportManage/index')), 'reportManage');
const reportBrand = r => require.ensure([], () => r(require('@/views/reportManage/reportBrand/index')), 'reportBrand');
const reportBrandDetail = r => require.ensure([], () => r(require('@/views/reportManage/reportBrand/reportBrandDetail/index')), 'reportBrandDetail');
const reportUser = r => require.ensure([], () => r(require('@/views/reportManage/reportUser/index')), 'reportUser');
const reportUserDetail = r => require.ensure([], () => r(require('@/views/reportManage/reportUser/reportUserDetail/index')), 'reportUserDetail');


export const constantRouterMap = [{
        path: '/login',
        component: login,
        hidden: true,
    }, {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        hidden: true,
        children: [{
            path: '/dashboard',
            component: home,
            meta: {
                title: '首页',
                noCache: true //如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
            },
        }]
    }, {
        path: '/register',
        component: Layout,
        redirect: '/register',
        hidden: true,
        children: [{
            path: '/register',
            component: register,
            name: 'register',
            meta: {
                title: '修改密码',
            }
        }]
    },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },
]

/* 初始路由 */
export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRouterMap
})

export const asyncRouterMap = [{
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
        path: '/dashboard',
        component: home,
        meta: {
            title: '首页',
        }
    }]
}]


/* 需要权限判断的路由 */
export const allRoutes = [{
        path: '/taskManage',
        component: Layout,
        name: 'taskManage',
        redirect: '/taskManage/taskEntry',
        alwaysShow: true, //显示根路由
        meta: {
            title: '任务',
            icon: 'icon-task',
        },
        children: [{
                path: 'taskEntry',
                component: taskManage,
                name: 'taskEntry',
                redirect: '/taskManage/taskEntry/taskentry',
                meta: {
                    title: '任务录入',
                },
                children: [{
                    path: 'taskentry',
                    component: taskEntry,
                    name: "taskentry",
                    meta: {
                        title: '任务录入'
                    }
                }, {
                    path: 'taskEntryItem',
                    component: taskEntryItem,
                    name: "taskEntryItem",
                    hidden: true,
                    meta: {
                        title: 'EVE'
                    }
                }]
            },
            {
                path: 'taskProgress',
                component: taskProgress,
                name: 'taskProgress',
                meta: {
                    title: '任务进度',
                }
            },
            {
                path: 'taskMine',
                component: taskMine,
                name: 'taskMine',
                meta: {
                    title: '我的审批',
                }
            },
            {
                path: 'taskHistory',
                component: taskHistory,
                name: 'taskHistory',
                meta: {
                    title: "任务历史"
                }
            }
        ]
    }, {
        path: '/userManage',
        component: Layout,
        redirect: '/userManage/userList',
        name: 'userManage',
        alwaysShow: true, //显示根路由
        meta: {
            title: '管理',
            icon: 'icon-manage',
        },
        children: [{
            path: 'userList',
            component: userManage,
            redirect: '/userManage/userList/userlist',
            name: 'userList',
            meta: {
                title: '员工管理',
            },
            children: [{
                path: 'userlist',
                component: userList,
                name: 'userlist',
                meta: {
                    title: '员工管理',
                }
            }, {
                path: 'leaderManage',
                component: leaderManage,
                name: 'leaderManage',
                hidden: true,
                meta: {
                    title: '组长管理',
                }
            }]
        }, {
            path: 'brandManage',
            component: brandManage,
            name: "brandManage",
            meta: {
                title: '品牌管理',
            }
        }, {
            path: 'materialManage',
            component: materialManage,
            name: "materialManage",
            meta: {
                title: '物料管理',
            }
        }, {
            path: 'costManage',
            component: costManage,
            name: "costManage",
            meta: {
                title: '成本中心管理',
            }
        }]
    }, {
        path: '/reportManage',
        component: Layout,
        name: 'reportManage',
        alwaysShow: true, //显示根路由
        meta: {
            title: '报表',
            icon: 'icon-form',
        },
        children: [{
            path: 'reportBrand',
            component: reportManage,
            name: 'reportBrand',
            meta: {
                title: '品牌报表',
            },
            children: [{
                path: 'reportbrand',
                component: reportBrand,
                meta: {
                    title: '品牌报表'
                }
            }, {
                path: 'reportBrandDetail',
                component: reportBrandDetail,
                hidden: true,
                meta: {
                    title: '品牌报表详情'
                }
            }]
        }, {
            path: 'reportUser',
            component: reportManage,
            name: 'reportUser',
            redirect: '/reportManage/reportUser/reportuser',
            meta: {
                title: '员工报表',
            },
            children: [{
                path: 'reportuser',
                component: reportUser,
                meta: {
                    title: '员工报表'
                }
            }, {
                path: 'reportUserDetail',
                component: reportUserDetail,
                hidden: true,
                meta: {
                    title: '员工报表详情'
                }
            }]
        }]
    }, //必须放最后
    {
        path: '*',
        redirect: '/404',
        hidden: true,
        meta: {
            title: '404',
        }
    }
]